package com.hdaccp.gymxmjpa.Controller;
import com.hdaccp.gymxmjpa.Dao.CoachDao;
import com.hdaccp.gymxmjpa.Service.CoachDaoImpl;
import com.hdaccp.gymxmjpa.entity.Coach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Controller
@RequestMapping("/coach")
public class CoachController {
   @Autowired
    private CoachDao coachDao;
   @Autowired
   private CoachDaoImpl coachDaoImpl;

    @RequestMapping("/jin3")
    public String jin3(){

        return "WEB-INF/jsp/coach";
    }

    @RequestMapping("/query")
    @ResponseBody
    public Map<String,Object> query(String coachname, int pageSize, int pageNumber){
        Map<String,Object>  map1=new HashMap<String,Object>();
        map1.put("coachname",coachname);
        map1.put("qi",(pageNumber-1)*pageSize);
        map1.put("shi",pageSize);
        return coachDaoImpl.query(map1);
    }
 @RequestMapping("/del")
    @ResponseBody
    public  Map<String,Object> del(long id,String coachname, int pageSize, int pageNumber){
     coachDao.deleteById(id);
     Map<String,Object>  map1=new HashMap<String,Object>();
     map1.put("coachname",coachname);
     map1.put("qi",(pageNumber-1)*pageSize);
     map1.put("shi",pageSize);
     return coachDaoImpl.query(map1);
    }
    @RequestMapping("/count")
    @ResponseBody
    public Long count (String coachName){
        coachDaoImpl.count(coachName);
        return  coachDaoImpl.count(coachName);
    }
    @RequestMapping("/add")
    @ResponseBody
    public  void save(Coach coach){
        coachDao.save(coach);
    }
    @RequestMapping("/cha")
    @ResponseBody
    public Optional<Coach> one(long id){
        return coachDao.findById(id);
    }
    @RequestMapping("/upd")
    @ResponseBody
    public  void upd(Coach coach){
        coachDao.save(coach);
    }


}
